package com.xmotor.girlspringbootstarter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(Girl.class)//当引入Girl类时创建
@EnableConfigurationProperties(GirlProperties.class)//让GirlProperties属性类生效
public class GirlAutoConfigure {

    @Autowired
    private GirlProperties girlProperties;

    @Bean
    @ConditionalOnMissingBean//当没有此实例时才创建
    @ConditionalOnProperty(prefix = "com.xmotor.girl",value = "isCreateGirl",havingValue = "true")//有这个值时才创建
    public Girl getGirl(){
        Girl girl = new Girl();
        girl.setName(girlProperties.getName());
        girl.setAge(girlProperties.getAge());
        girl.setFace(girlProperties.getFace());
        return girl;
    }
}
